package com.oopnet.template.demo.ws.soap_cxf;


import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.junit.Test;

public class CXFClient {
	
	/** 1.            通用动态代理配置   （也适用与sample方式发布的ws）          **/
	public static void main(String[] args) {
		DynamicClientFactory factory = DynamicClientFactory.newInstance();
		Client client = factory.createClient("http://localhost:8080/template/ws/soap/hello?wsdl");
		
		try {
			Object result[] = client.invoke("say", "World !");
			System.out.println(result[0]);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/** 2.             静态代理客户端 （这种方式需要通过WSDL打客户端jar包，最原始的一种做法，少用）                 **/
	@Test
	public void testStaticProxy() throws Exception {
		JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
		factoryBean.setAddress("http://localhost:8080/template/ws/soap/hello?wsdl");
		factoryBean.setServiceClass(HelloService.class);
		HelloService service = factoryBean.create(HelloService.class);
		String result = service.say("World");
		System.out.println(result);
	}
	
	/** 3.             动态代理客户端   （不适用与sample方式发布的ws）             **/
	@Test
	public void testDynamicProxy() throws Exception {
		 JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
	     Client client = factory.createClient("http://localhost:8080/template/ws/soap/hello?wsdl");

	        try {
	            Object[] results = client.invoke("say", "World!");
	            System.out.println(results[0]);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	}
	
	/** 4.            基于Spring配置bean的方式 【http://my.oschina.net/huangyong/blog/286439】            **/
	
}
